﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.waitingQueue {
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.models.world.*;

    public class CreateWaitingPetCommand extends Command {

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var worldFactory:WorldFactory;
		[Inject]
        public var worldModel:WorldModel;
		[Inject]
        public var userModel:UserModel;
		[Inject]
        public var tutorialModel:TutorialModel;

        override public function execute():void{
            var _local1:Object = this.event.info;
            _local1.workflow_state = GameConstants.STATE_WAITING_QUEUE;
            _local1.queueIndex = this.event.id;
            var _local2:IActing = this.worldFactory.createActor(_local1);
            this.setActor(_local2);
        }
        private function setActor(_arg1:IActing):void{
            if (!this.worldModel.getActor(_arg1.id)){
                this.worldModel.addActor(_arg1);
            };
            dispatch(new InfoEvent(EventConstants.CREATE_WAITING_PET_VIEW, null, _arg1));
            var _local2:IRoom = (this.worldModel.getRoomById(_arg1.roomId) as IRoom);
            var _local3:int = (this.tutorialModel.isInTutorialMode) ? 2200 : 4000;
            var _local4:Point = new Point((_local3 + Numbers.randomIntBetween(500, 1500)), 200);
            dispatch(new InfoEvent(EventConstants.SET_TO_POSITION, _arg1.id, _local4));
            if (this.userModel.level > 1){
                dispatch(new InfoEvent(EventConstants.WALK_TO_QUEUE, _arg1.id));
            };
        }

    }
}//package net.wooga.pets.controllers.waitingQueue 
